package cn.anc.aonicardv.module.ui.my;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cn.anc.aonicardv.R;
import cn.anc.aonicardv.module.adpter.recorder.RtspLogAdapter;
import cn.anc.aonicardv.module.ui.base.BaseActivity;
import cn.anc.aonicardv.util.FileUtils;
import cn.anc.httpcontrolutil.cache.CacheManager;

/**
 * function :
 * </p>
 *
 * @author: aoni123@anc.cn
 * @date: 2021/5/12
 */
public class LogActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_loginfo);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initVariable() {
    }

    @Override
    public void setListener() {
    }

    private TextView  mTitleTv;
    private RecyclerView RvRtspLog;
    private RtspLogAdapter mRtspLogAdapter;
    private List<String> mLogList  = new ArrayList<>();
    @Override
    public void initData() {
        findViewById(R.id.tv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTitleTv = (TextView) findViewById(R.id.tv_title);

        mTitleTv.setText("日志查看");

        RvRtspLog = (RecyclerView) findViewById(R.id.rv_rtsp_log);
        mRtspLogAdapter = new RtspLogAdapter(this);
        RvRtspLog.setLayoutManager(new LinearLayoutManager(this));
        RvRtspLog.setAdapter(mRtspLogAdapter);

        try {
            List<String> list = FileUtils.readFileToList(CacheManager.CACHE_ROOT_DIR + "/" + "rtspLog" + ".txt");
            if (null!=list&&list.size()>0){
                mLogList.clear();
                mLogList.addAll(list);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        mRtspLogAdapter.setData(mLogList);
        RvRtspLog.scrollToPosition(mRtspLogAdapter.getItemCount()-1);

    }




}
